Kth Largest Element in an Array
Question
Given an array of integers, find the kth largest element in the array.
Example 1
Input: [3,2,1,5,6,4]
k = 2
Output: 5
Solution
- ▭
- ▯
all//Kth Largest Element in an Array.py
def kthLargestElement(arr, k):
arr.sort(reverse = True)
return arr[k-1]
# Driver Code
arr = [12, 3, 5, 7, 19]
k = 2
print(kthLargestElement(arr, k))
all//Kth Largest Element in an Array.py
def kthLargestElement(arr, k):
arr.sort(reverse = True)
return arr[k-1]
# Driver Code
arr = [12, 3, 5, 7, 19]
k = 2
print(kthLargestElement(arr, k))